//引入vue-router
import { createRouter, createWebHashHistory } from 'vue-router'
//ES6  import输入  export 输出
// 模块化 默认私有，如何被别人使用？
// 通过export 输出
// 如何使用
// export default 默认输出
import Index from '@/views/static/index.vue'
import LayoutAdmin from '@/layout/admin/index.vue'
//白名单
const whiteList = [
    "/",
    "/login",
    "/cms_subject_category"
]
import { useUserStore } from '../store/user'

//路由表
const routes = [
    {
        path: '/',//访问路径 http://127.0.0.1:5173/cx/XfDGdOkjVo7deIxQjurcf8BEnNf
        name: 'home', //命名路由
        component: Index,   //key:value  默认//页面组件 components 普通组件 页面组件和普通组件是一对多
    },
    {
        path: '/adcate',
        name: 'adCate',
        component: () => import('../views/static/adCate.vue')// 懒加载
    },

    {
        path: '/sms-flash-promotion',
        name: 'sms-flash-promotion',
        component: () => import('@/views/admin/sms-flash-promotion.vue'), // 懒加载
      },
      {
        path: '/sms_home_advertise',
        name: 'smshome',
        component: () => import('../views/static/sms_home_advertise.vue')// 懒加载
    },
    {
        path: '/ums_resource_category',
        name: 'ums_resource_category',
        component: () => import('../views/admin/ums_resource_category.vue')// 懒加载
    },
      {
        path: '/cms_topic',
        name: 'cms_topic',
        component: () => import('../views/admin/cms_topic.vue')// 懒加载
    },
    {
        path: '/ums-member-level',
        name: 'ums-member-level',
        component: () => import('../views/admin/ums-member-level.vue')// 懒加载
    },
    {
        path: '/ums_member_receive_address',
        name: 'ums_member_receive_address',
        component: () => import('../views/admin/ums_member_receive_address.vue')// 懒加载
    },
    {
        path: '/sms_coupon',
        name: 'smsCoupon',
        component: () => import('../views/static/sms_coupon.vue')// 懒加载
    },
    {
        path: '/cms_subject_category',
        name: 'cms_subject_category',
        component: () => import('../views/static/cms_subject_category.vue')// 懒加载
    },
    {
        path: '/pms_product_category',
        name: 'pms_product_category',
        component: () => import('../views/static/pms_product_category.vue')// 懒加载
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('../views/static/login.vue')// 懒加载
    },
    {
        path: '/pms_comment_replay',
        name: 'pms_comment_replay',
        component: () => import('@/views/admin/pms-comment-replay.vue')// 懒加载
    },
    {
        path: '/oms-company-address',
        name: 'oms-company-address',
        component: () => import('@/views/admin/oms-company-address.vue')// 懒加载
    },
    {
        path: '/admin',
        name: 'admin',
        component: LayoutAdmin,
        children: [
            {
                path: '',
                name: 'admin-index',
                component: () => import('@/views/admin/index.vue')
            },
            {
                path: 'info',
                name: 'admin-info',
                component: () => import('@/views/admin/info.vue')
            },
            {
                path: 'logout',
                name: 'admin-logout',
                component: () => import('@/views/admin/logout.vue')
            }, {
                path: 'changepassword',
                name: 'admin-changepassword',
                component: () => import('@/views/admin/changepassword.vue')
            },
            {
                path: 'forgetpassword',
                name: 'admin-forgetpassword',
                component: () => import('@/views/admin/forgetpassword.vue')
            },
            {
                path: 'memberTask',
                name: 'admin-memberTask',
                component: () => import('@/views/admin/memberTask.vue')
            },
<<<<<<< HEAD
             {
                path: 'admininfo',
                name: 'admin-admininfo',
                component: () => import('@/views/admin/admininfo.vue')
            },
            {
                path: 'pms_album',
                name: 'admin-pms_album',
                component: () => import('@/views/admin/pms_album.vue')
            },
            {
                path: 'pms_comment',
                name: 'admin-pms_comment',
                component: () => import('@/views/admin/pms_comment.vue')
            },
            {
                path: 'oms-order-setting',
                name: 'admin-oms-order-setting',
                component: () => import('@/views/admin/oms-order-setting.vue')
            }
            
=======
>>>>>>> f3c03c7 (2003010362符)


        ]
    },



    {
        path: '/:pathMatch(.*)*',
        name: '404',
        component: () => import('../views/404.vue')// 懒加载
    }

]
const router = createRouter({
    //模式
    history: createWebHashHistory(),
    routes
})
//前置路由守卫
//用户状态 user.js
router.beforeEach((to, from, next) => {
    const userStore = useUserStore();

    if (whiteList.includes(to.path)) {
        next();
    }
    else {

        if(userStore.token&&userStore.token.length>0){
            next()
        }
        else{
           next({name:"login"})
        }

    }


})
export default router;
